package com.ruoyi.iot.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iot.domain.FacDevicesMonitor;
import com.ruoyi.iot.service.IFacDevicesMonitorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备类型监测Controller
 * 
 * @author rww
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/iot/monitor")
public class FacDevicesMonitorController extends BaseController
{
    @Autowired
    private IFacDevicesMonitorService facDevicesMonitorService;

    /**
     * 查询设备类型监测列表
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(FacDevicesMonitor facDevicesMonitor)
    {
        startPage();
        List<FacDevicesMonitor> list = facDevicesMonitorService.selectFacDevicesMonitorList(facDevicesMonitor);
        return getDataTable(list);
    }
    /**查询设备型号监测类型列表-不带分页**/
    @GetMapping("/listNoPage")
    public AjaxResult listNoPage(FacDevicesMonitor facDevicesMonitor){
        List<FacDevicesMonitor> list = facDevicesMonitorService.selectFacDevicesMonitorList(facDevicesMonitor);
        return AjaxResult.success(list);
    }
    /**
     * 导出设备类型监测列表
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:export')")
    @Log(title = "设备类型监测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FacDevicesMonitor facDevicesMonitor)
    {
        List<FacDevicesMonitor> list = facDevicesMonitorService.selectFacDevicesMonitorList(facDevicesMonitor);
        ExcelUtil<FacDevicesMonitor> util = new ExcelUtil<FacDevicesMonitor>(FacDevicesMonitor.class);
        util.exportExcel(response, list, "设备类型监测数据");
    }

    /**
     * 获取设备类型监测详细信息
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(facDevicesMonitorService.selectFacDevicesMonitorById(id));
    }

    /**
     * 新增设备类型监测
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:add')")
    @Log(title = "设备类型监测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FacDevicesMonitor facDevicesMonitor)
    {
        return toAjax(facDevicesMonitorService.insertFacDevicesMonitor(facDevicesMonitor));
    }

    /**
     * 修改设备类型监测
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:edit')")
    @Log(title = "设备类型监测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FacDevicesMonitor facDevicesMonitor)
    {
        return toAjax(facDevicesMonitorService.updateFacDevicesMonitor(facDevicesMonitor));
    }

    /**
     * 删除设备类型监测
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:remove')")
    @Log(title = "设备类型监测", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(facDevicesMonitorService.deleteFacDevicesMonitorByIds(ids));
    }
    @PostMapping("setMonitorType")
    public AjaxResult setMonitorType(@RequestBody FacDevicesMonitor dto){
        int count=facDevicesMonitorService.setMonitor(dto);
        return AjaxResult.success(count);
    }

    @PostMapping("setMonitorParam")
    public AjaxResult setMonitorParam(@RequestBody FacDevicesMonitor dto){
        //效验数据
        int count=facDevicesMonitorService.setMonitorParam(dto);
        return AjaxResult.success(count);
    }
}
